#include <stdio.h>

#define MAXLEN 1010

char str[MAXLEN], ch[MAXLEN];

int main(){
    while (1)
    {
        fgets(ch, MAXLEN, stdin);
        fgets(str, MAXLEN, stdin);
        if (ch[0] == '#') break;

        int i, count[256];
        for (i = 0; i < 256; i++)
            count[i] = 0;

        for (i = 0; str[i]; i++) {
            count[str[i]]++;
        }

        for (i = 0; ch[i]; i++)
            if (ch[i] != '\r' && ch[i] != '\n') //fgets读取进来的字符包含回车
                printf("%c %d\n", ch[i], count[ch[i]]);
    }
    return 0;
}

